/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author stephane
 */
public class AltaRicaModelManager 
{
    private static AltaRicaModelManager _instance = null;
    private static AltaRicaModel _currentModule = null;
    
    protected AltaRicaModelManager()
    {
        
    }
    private ArrayList<AltaRicaModel> _models = new ArrayList<AltaRicaModel>();
    public static AltaRicaModel getCurrentModel() {
        return _currentModule;
    }
    public static void setCurrentModel(AltaRicaModel model) {
    	_currentModule = model;
    }
    public static AltaRicaModelManager getInstance()
    {
        if (_instance == null) {
            _instance = new AltaRicaModelManager();
        }
        return _instance;
    }
    
    public void addModel(AltaRicaModel model)
    {
        AltaRicaModel found = null;
        for (AltaRicaModel pm : _models)
        {
            if (pm.getAst().getFileName().equals(model.getAst().getFileName()))
            	found = pm;
        }
        if (found != null)
        {
            this._models.remove(found);
        }
        this._models.add(model);
        _currentModule = model;
    }
    public List<AltaRicaModel> getModels()
    {
        return Collections.unmodifiableList(_models);
    }
    
    public AltaRicaModel getModel(String fileName)
    {
        for(AltaRicaModel model : _models)
        {
            if (model.getAst().getFileName().equals(fileName)
            		|| model.getAst().getFileName().endsWith(fileName)) {
                return model;
            }
        }
        return null;
    }
}
